23
"Luke"
true
["Joe", "Flora"]
{age: 23}
o=> print ("Hello world")
Anything that can have its own properties
["Joe", "Flora"]
{age: 23}
o=> print ("Hello world")
Anything that cannot have its own properties
23 "Luke" true
Anything that has iterable properties
"Luke"
["Joe", "Flora"]
{age: 23}
o=> print ("Hello world")
Int Odd Even Positive Negative
UpperCase LowerCase Capitalised
Num[_]
Text[_]
class Person {}
Person[_]
"Luke".is (Text) == true
"Luke".is (Array) == true
"Luke".is (Thing) == true
23.is (Num) == true
23.is (Num.Odd) == true
class Person {}
var luke = new Person
luke.is (Person) == true
"6".as (Num) == 6
23.as (Text) == "23"
"Hi".as (List) == ["H", "i"] //unimplemented
"Luke".as (Type) == Text
[2, 3].as (Type) == List
class Person {}
var luke = new Person
luke.as (Type) == Person
Num.O.multiply = function(num) => {
return this * num
}
3.multiply(2) == 6
Text[_].O.shout = function() {
this.o.forEach.x= text => print (text.as(UpperCase))
}
["Joe", "Flora"].shout() // "JOE" "FLORA"
Even.O.getHalf = function () {
return this / 2
}
4.getHalf() == 2
Immediately calls a block of code
x=o=> print ("Hello world")
x=o=> {
print ("Hello")
print ("Goodbye")
}
Creates a function with no parameters
var hello = o=> print ("Hello world")
var greet = o=> {
print ("Hello")
print ("Goodbye")
}
For an optional parameter that won't cause reference errors
var greet = (name =x){
if (name.Type == Text) say ("Hello " + name)
else say ("Hello")
}
Binds some arguments to a function
var looper = loop.o(10)
looper (num => {
print ("Counting to 10")
print ("I've got up to " + num)
})
Binds something to a method
var friends = ["Joe", "Flora"]
var friendLooper = friends.o.forEach
friendLooper (friend => {
print ("Hello " + friend)
})
Calls some code with an argument
print. x= "Hello world"
names.o.forEach.x= name => {
print ("Hello " + name)
print ("Goodbye " + name)
}
loop.o(10).x= num => {
print ("Counting to 10")
print ("I've got up to " + num)
}
print ("Hello world")
test (age == 23) test (2 + 2 == 5, "Something is very wrong!")
Compare something to a template
(better match = lower rating)
Compare(2, 2).type == "exact"
Compare("hi", Text).type == "type"
Compare(3, Text).type == false
Compare([3, 2], [Num, 2]).type == "structure"
Compare(a => a+1, a => {}).type == "structure"
Compare({age: 23}, {age: Num}).type == "structure"
Compare(2, 2).rating < Compare(2, Num).rating
Matches a thing to a pattern
var response = match (input,
Num, "That's a number",
42, "That's a specific number",
[Text, Text], "That's an array of two strings",
_, "It's something else",
)
name.match (
"Luke", o=> print ("It's me!"),
"Flora", o=> print ("It's you!")
)
Creates a function that matches its arguments
var fibonacci = matcher ( [0], 0, [1], 1, [Num], n => fibonacci(n-1) + fibonacci(n-2), )
._.todeCreates a tode property
function Person (name, surname){
this.name = name
this.surname = surname
this._.fullname.get = o=> this.name + " " + this.surname
}
var luke = new Person("Luke", "Wilson")
luke.fullname == "Luke Wilson"
Adds up a list of numbers
[2, 3].sum == 5
Multiplies together a list of numbers
[2, 3].product == 6
Finds the average of a list of numbers
[2, 3].mean == 2.5
15.isMultipleOf (3) == true
3.isFactorOf (15) == true
var name = ask ("What is your name?")
var age = ask ("How old are you?").Num
say (`Next year you will be ${age+1} years old ${name}`)
[10, to, 0].o.forEach.x= matcher (
[0], o => print ("Blast off!"),
[ ], n => print (n),
)
var fibonacci = matcher ( [0], 0, [1], 1, [Num], n => fibonacci(n-1) + fibonacci(n-2), )
var factorial = matcher ( [0], 1, [Num], n => n * factorial(n-1), )
var fizzbuzz = n => match ( n.isMultipleOf (15), "Fizzbuzz", n.isMultipleOf (5), "Buzz", n.isMultipleOf (3), "Fizz", _, n.as(Text) )